package com.zxp.springcloud.controller;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.zxp.springcloud.entities.CommonResult;
import com.zxp.springcloud.entities.Payment;
import com.zxp.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @description:
 * @author: 张新朋
 * @time: 2020/4/30 16:32
 */
@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/payment/create")
    public CommonResult<Payment> create(@RequestBody Payment payment){
        int result = paymentService.create(payment);
        log.info("数据库插入结果:",result);
        if(result > 0){
            return new CommonResult(200,"插入数据成功,serverPort:"+serverPort,result);
        }else{
            return new CommonResult(400,"插入数据失败,serverPort:"+serverPort,null);
        }
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id){
        Payment result = paymentService.selectById(id);
        System.out.println("数据查询成功");
        log.info("数据库查询结果:",result);
        if(null != result){
            return new CommonResult(200,"查询结果成功,serverPort:"+serverPort,result);
        }else{
            return new CommonResult(400,"查询数据失败,serverPort:"+serverPort,null);
        }
    }
    @GetMapping(value = "/payment/lb")
    public String getPaymentLB() {
        return serverPort;
    }

}